Skip to content

fix(bot): fix Telegram channel init crash and empty content for Claude#421

Open
ponsde wants to merge 3 commits intovolcengine:mainfrom
ponsde:fix/telegram-init-and-empty-content
Open

fix(bot): fix Telegram channel init crash and empty content for Claude#421
ponsde wants to merge 3 commits intovolcengine:mainfrom
ponsde:fix/telegram-init-and-empty-content

Conversation

@ponsde
Copy link
Contributor

@ponsde ponsde commented Mar 4, 2026

Summary

Fix two bugs that prevent Telegram channel and Claude models from working correctly in vikingbot:

  1. TelegramChannel.init NameError (channels/telegram.py): The super().__init__() call references **kwargs, but kwargs is not defined in the method signature. This causes an immediate NameError when the Telegram channel is instantiated, making it completely unusable. Also fixes the type hint from undefined TelegramConfig to the already-imported TelegramChannelConfig.

  2. Empty content block rejected by Claude (agent/context.py): When the LLM responds with only tool_calls and no text, content is None. The expression content or "" produces an empty string "", which Claude/Anthropic API rejects with 400 Bad Request ("text content blocks must be non-empty"). Fixed by only including the content field when it is non-empty.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

  • Tested Telegram bot end-to-end with Claude (Opus 4-6) via custom API proxy
  • Verified Telegram channel starts without NameError
  • Verified multi-turn conversations with tool calls work on Claude models
  • Confirmed no regression on non-Telegram channels (Feishu pattern unchanged)

Checklist

  • Code follows the project's style guidelines (Ruff, 100 char line width)
  • Changes are minimal and focused on the bug fixes
  • No new dependencies added
  • Tested with real Telegram bot instance

groq_api_key: str = "",
):
super().__init__(config, bus, **kwargs)
super().__init__(config, bus)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] workspace_path 未传递给 BaseChannel.__init__,导致 self.workspace_path 始终为 None,媒体文件会下载到 ~/.vikingbot/media 回退路径而非 workspace 目录。

这是预先存在的问题(原代码因 NameError 根本无法运行),但既然 TelegramChannel 现在可以正常工作了,建议一并修复:

  1. __init__ 中添加 workspace_path 参数:
def __init__(
    self,
    config: TelegramChannelConfig,
    bus: MessageBus,
    groq_api_key: str = "",
    workspace_path: Path | None = None,
):
    super().__init__(config, bus, workspace_path)
  1. manager.py 实例化时传递 workspace_path
channel = TelegramChannel(
    channel_config,
    self.bus,
    groq_api_key=additional_deps.get("groq_api_key"),
    workspace_path=workspace_path,
)

@ponsde
Copy link
Contributor Author

ponsde commented Mar 5, 2026

@qin-ctx 感谢建议!已在 9bcd4d6 中添加 workspace_path 参数到 TelegramChannel.__init__ 并在 ChannelManager 中传递,与其他 channel 保持一致。同时修复了 CI lint 失败的 ruff 格式问题。

@qin-ctx
Copy link
Collaborator

qin-ctx commented Mar 5, 2026

@qin-ctx 感谢建议!已在 9bcd4d6 中添加 workspace_path 参数到 TelegramChannel.__init__ 并在 ChannelManager 中传递,与其他 channel 保持一致。同时修复了 CI lint 失败的 ruff 格式问题。

没别的问题,辛苦处理下代码冲突,然后@我合并~

ponsde and others added 3 commits March 5, 2026 13:38
TelegramChannel.__init__ references **kwargs in super().__init__() call,
but kwargs is not in the method signature. This causes a NameError when
the Telegram channel is instantiated, making it completely unusable.

Also fixes the type hint from undefined TelegramConfig to the correct
TelegramChannelConfig which is already imported.
…bility

When the LLM responds with only tool_calls and no text, content is None.
The expression `content or ""` produces an empty string, which Claude's
API rejects with 400 Bad Request ("text content blocks must be non-empty").

Only include the content field when it is non-empty.
Add workspace_path parameter to TelegramChannel.__init__ and forward to
BaseChannel, consistent with all other channel types. Fix ruff format
issues in context.py and manager.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ponsde ponsde force-pushed the fix/telegram-init-and-empty-content branch from 9bcd4d6 to 297e33a Compare March 5, 2026 13:39
@ponsde
Copy link
Contributor Author

ponsde commented Mar 5, 2026

@qin-ctx 已 rebase 解决冲突,辛苦 review,没注意 main 更新了这么多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants